import uuid
from django.db import models
from apps.utils.base_model import BaseModel
from apps.utils.enums import RedEnvelopEnum, RedEnvelopSendStatusEnum, RedEnvelopReceiveIsWithdrawEnum


class ActionTab(BaseModel):
    """ 主页任务表 """

    created_by = models.UUIDField(
        null=True,
        default=uuid.uuid4,
        editable=False,
        blank=False,
        db_index=True,
        help_text="创建人",
        verbose_name="创建人",
    )

    description = models.TextField(
        null=False,
        blank=True,
        default="",
        verbose_name="动作描述信息",
        help_text="动作描述信息",
    )

    image_url = models.CharField(
        max_length=255,
        null=False,
        blank=False,
        default="",
        verbose_name="动作图片Url",
        help_text="动作图片Url",
    )

    class Meta:
        db_table = "red_envelop_action_tab"


class RedEnvelop(BaseModel):
    """ 红包记录表 """

    out_trade_no = models.CharField(
        max_length=255,
        null=False,
        blank=False,
        default="",
        unique=True,
        verbose_name="关联微信支付的交易订单号",
        help_text="关联微信支付的交易订单号",
    )

    send_user_id = models.UUIDField(
        null=False,
        default=None,
        blank=False,
        db_index=True,
        verbose_name="发送红包的用户uuid",
        help_text="发送红包的用户uuid",
    )

    title = models.CharField(
        max_length=255,
        null=False,
        blank=False,
        default="",
        verbose_name="发送红包的名称",
        help_text="发送红包的名称",
    )

    amount = models.DecimalField(
        max_digits=10,
        decimal_places=2,
        null=False,
        blank=False,
        default=0,
        verbose_name="发送红包的金额",
        help_text="发送红包的金额",
    )

    count = models.IntegerField(
        null=False,
        blank=False,
        default=0,
        verbose_name="发送红包的数量",
        help_text="发送红包的数量",
    )

    is_paid = models.SmallIntegerField(
        choices=RedEnvelopEnum.choices(),
        default=RedEnvelopEnum.NoWithdrawal,
        null=False,
        blank=False,
        verbose_name="是否支付/提现",
        help_text="是否支付/提现",
    )

    action_id_list = models.CharField(
        max_length=255,
        null=False,
        blank=False,
        default="",
        verbose_name="红包动作列表",
        help_text="红包动作列表",
    )

    pre_allocated_amount_of_cent_list = models.CharField(
        max_length=1024,
        null=False,
        blank=False,
        default="",
        verbose_name="每个红包金额",
        help_text="每个红包金额",
    )

    total_receive_amount_of_cent = models.DecimalField(
        max_digits=10,
        decimal_places=2,
        null=False,
        blank=False,
        default=0,
        verbose_name="已经领取的红包金额",
        help_text="已经领取的红包金额",
    )

    total_receive_count = models.IntegerField(
        null=False,
        blank=False,
        default=0,
        verbose_name="已经领取的红包数量",
        help_text="已经领取的红包数量",
    )

    send_status = models.SmallIntegerField(
        choices=RedEnvelopSendStatusEnum.choices(),
        null=False,
        blank=False,
        default=RedEnvelopSendStatusEnum.NotGetOverWithNotExpired,
        verbose_name="红包领取状态",
        help_text="红包领取状态",
    )

    class Meta:
        db_table = "red_envelop_bags"


class RedEnvelopReceive(BaseModel):
    """ 红包领取表 """

    red_envelop_uuid = models.UUIDField(
        null=False,
        default=None,
        blank=False,
        db_index=True,
        verbose_name="红包ID",
        help_text="红包ID",
    )

    receive_user_uuid = models.UUIDField(
        null=False,
        default=None,
        blank=False,
        db_index=True,
        verbose_name="领取红包的用户uuid",
        help_text="领取红包的用户uuid",
    )

    receive_action_uuid = models.UUIDField(
        null=False,
        default=None,
        blank=False,
        verbose_name="领取红包的挑战动作",
        help_text="领取红包的挑战动作",
    )

    receive_amount_of_cent = models.DecimalField(
        max_digits=10,
        decimal_places=2,
        null=False,
        blank=False,
        default=0,
        verbose_name="领取红包金额",
        help_text="领取红包金额",
    )

    receive_sequence_number = models.IntegerField(
        null=False,
        blank=False,
        default=0,
        verbose_name="领取红包顺序编号",
        help_text="领取红包顺序编号",
    )

    receive_timestamp = models.DateTimeField(
        null=False,
        blank=False,
        default=None,
        verbose_name="领取红包时间",
        help_text="领取红包时间",
    )

    is_withdraw = models.SmallIntegerField(
        choices=RedEnvelopReceiveIsWithdrawEnum.choices(),
        default=RedEnvelopReceiveIsWithdrawEnum.NoWithdrawal,
        null=False,
        blank=False,
        verbose_name="是否提现",
        help_text="是否提现",
    )

    withdraw_time = models.DateTimeField(
        null=False,
        blank=False,
        default=None,
        verbose_name="提现时间",
        help_text="提现时间",
    )

    class Meta:
        db_table = "red_envelop_receive"
